/*
 * @Description: 路由
 * @Version: 2.0
 * @Autor: hzj
 * @Date: 2023-05-18 20:14:47
 * @LastEditors: hzj
 * @LastEditTime: 2023-05-19 23:19:54
 */
import React, { lazy } from 'react'
import { Navigate } from "react-router-dom"
const widthLoadingComponent = (comp: JSX.Element) => (
    <React.Suspense fallback={<div>Loading...</div>}>
        {comp}
    </React.Suspense>)
import Home from '../views/home'
const Login = lazy(() => import('@/views/login'))
const WorkPlace = lazy(() => import('@/views/workplace'))
const DashBoaed = lazy(() => import('@/views/dashBoard'))
const Loading = lazy(() => import('@/views/dashBoard/loading'))

//children数组
const children = [
    {
        path: '/workplace',
        element: widthLoadingComponent(<WorkPlace />)
    },
    {
        path: '/dashBoard',
        element: widthLoadingComponent(<DashBoaed />)
    },
]

// //权限点数组不包含的,就把路径改成*
const usedMenu = JSON.parse(localStorage.getItem("usedMenu"))

if (usedMenu) {
    for (let i = children.length - 1; i >= 0; i--) {
        if (!usedMenu.includes(children[i].path)) {
            children[i].path = '*'
        }
    }
}
// console.log(children)


const routes = [
    {
        path: '/',
        element: widthLoadingComponent(<Loading />)
    },
    {
        path: '/login',
        element: widthLoadingComponent(<Login />)
    },
    {
        path: '/',
        element: <Home />,
        children,
    },
    {
        path: '*',
        element: <Navigate to="/" />
    },
]

export default routes